<?php

/**
 * @return array $_GET or $_POST depending on current HTTP method.
 */
function getRequestParams() {
	$params = array();
	$httpMethod = $_SERVER["REQUEST_METHOD"];
	if ($httpMethod === "GET") {
		$params = $_GET;
	} else if ($httpMethod === "POST") {
		$params = $_POST;
	}
	return $params;
}

/**
 * @param string $paramName
 * @param string $default
 * 
 * @return string Value of request param or $default value.
 */
function getRequestParam($paramName, $default = null) {
	$paramValue = null;
	$params = getRequestParams();
	if (array_key_exists($paramName, $params)) {
		$paramValue = $params[$paramName];
	} else {
		$paramValue = $default;
	}
	return $paramValue;
}

/**
 * @param GG_API_SimpleMethod $method Common configuration that can be run
 * against every method in this example.
 */
function configApiMethod($method) {
	if ($method instanceof GG_API_SimpleMethod) {
		$method->setFormat(getRequestParam('format'));
		$method->setUseRequestParams(true);
	}
}

?>
